package com.freshmarket.freshmarket.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.freshmarket.freshmarket.entity.Product;
import com.freshmarket.freshmarket.service.IProductService;
import com.freshmarket.freshmarket.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Squirrel
 * @since 2020-09-04
 */
@RestController
@Slf4j
public class ProductController {
    @Autowired
    private  IProductService iProductService;
    @GetMapping("/productBytype")
    public Result All(String productType){
    List<Product> products=iProductService.selectProduct(productType);

        return Result.successResult(products);
    }
    @RequestMapping("/productAll")
    public Result productAll(){
        List<Product> list=iProductService.selectAllProduct();

        return Result.successResult(list);
    }
    @RequestMapping("/selectByTypeandName")
    public  Result selectBytypeandName(@RequestParam(defaultValue = "1") int pageIndex, @RequestParam(defaultValue = "4") int pageSize,String productName,String productType){



        IPage<Product> iPage=iProductService.selectp(pageIndex,pageSize,productName,productType);


        return Result.successResult(iPage);


    }
}

